<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/9/13
  Time: 10:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/include.jsp" %>
<html>
<head>
    <title>Title</title>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">
    <form class="form-horizontal" id="demandForm" name="demandForm">
        <input type="hidden" id="demId" name="demId" value="${tBugSource.id}">
        <input type="hidden" id="statusText" name="statusText" value="${tBugSource.statusText}">
        <div class="tabs-container">
            <fieldset>
                <div class="form-group">

                    <!-- 部门列表-->

                    <label class="col-sm-2 control-label">转移部门*：</label>
                    <div class="col-sm-4">
                        <select onchange="getDepartmentManager()" class="form-control" name="department"
                                id="department">
                            <option>请选择--</option>
                            <c:forEach items="${departmentList}" var="det">
                                <option value="${det.id}">${det.name}</option>

                            </c:forEach>
                        </select>
                    </div>


                </div>
                <div class="form-group">
                    <!-- 部门项目经理-->

                    <label class="col-sm-2 control-label">项目经理*：</label>
                    <div class="col-sm-4">
                        <select class="form-control" name="principal" id="principal">
                            <option selected>请选择--</option>
                        </select>
                    </div>


                </div>


                <div class="form-group">
                    <label class="col-sm-2 control-label">转移原因：</label>
                    <div class="col-sm-7">
                                    <textarea id="remark" name="remark"
                                              class="form-control"
                                              rows="5"></textarea>
                    </div>
                </div>

            </fieldset>
            <fieldset>
                <div class="form-group">
                    <div class="col-sm-7" style="text-align: center;">

                        <input value="提交" class="btn  btn-primary" type="button" id="submitBtn">
                        <button id="closeBut" onclick="closeWin()" class="btn  btn--white" type="button">关闭</button>
                    </div>
                </div>
            </fieldset>
        </div>
    </form>
</div>


<script>

    $(document).ready(function () {

        $("#demandForm").validate({
            rules: {
                department: {
                    min:0
                },
                principal: {
                    min:0
                }
            },
            messages: {
                department: {
                    min: '请选择部门'
                },
                principal: {
                    min: '请选择项目经理'
                }
            }
        });
    });


    $("#submitBtn").click(function () {

        if ($("#demandForm").valid()) {

            var remark = $("#remark").val();
            var demandId = $("#demId").val();
            var statusText = $("#statusText").val();
            var department = $("#department").find("option:selected").text();
            var departmentId = $("#department").val();

            var receiverName = $("#principal").find("option:selected").text();
            var receiverId = $("#principal").val();


            var args = {
                "statusText": statusText,
                "demandId": demandId,
                "remark": remark,
                "department": department,
                "departmentId": departmentId,
                "receiverName": receiverName,
                "receiverId": receiverId
            }

            var url = "transferBug.html";
            //加载进度条
            layer.load(2, {
                shade: [0.2, '#999999'] //0.1透明度的白色背景
            });
            $.post(url, args, function (data) {
                data = jQuery.parseJSON(data);
                //保存成功
                if (data.code == 1) {
                    layer.closeAll('loading');
                    layer.alert(data.msg,
                        function () {
//                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
//                        parent.layer.close(index); //再执行关闭
                            parent.location.reload();
                        });


                } else {
                    //失败
                    layer.alert("失败");
                    layer.closeAll('loading');
                }
            });
        }
    });


    function closeWin() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    }




    //部门关联人员
    function getDepartmentManager() {
        var department = $("#department").val();

        var args = {
            "departmentId": department
        };

        var url = "getManagerByDepartmentId.html"
        //加载进度条
        layer.load(2, {
            shade: [0.2, '#999999'] //0.1透明度的白色背景
        });
        $.post(url, args, function (data) {
            data = jQuery.parseJSON(data);

            //保存成功
            if (data.code == 1) {
                layer.closeAll('loading');
                var users = data.body;

                var htmlStr = "";
                for (var i = 0; i < users.length; i++) {
                    htmlStr += "<option value='" + users[i].id + "'>" + users[i].realName + "</option>"
                }

                $("#principal").html(htmlStr);

            } else {
                //失败
                layer.closeAll('loading');
            }
        });


    }
</script>
</body>
</html>
